﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public class ComConnectionHelper
    {
        #region 打开数据库连接SQL
        public static void OpenConection_SQL(ref SqlConnection conn_sql)
        {
            try
            {
                if (conn_sql.State == System.Data.ConnectionState.Closed)
                {
                    conn_sql.Open();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 关闭数据库连接SQL
        public static void CloseConnection_SQL(ref SqlConnection conn_sql)
        {
            try
            {
                if (conn_sql.State == System.Data.ConnectionState.Open)
                {
                    conn_sql.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 获取SPMS数据库连接字符串
        private static string GetConnectionString_SPMS()
        {
            try
            {
                string ConnectionString = "Persist Security Info=False;User ID=sa;Password=123456;Initial Catalog=CategoryMSdb;Max Pool Size=512;Data Source=.";
                return ConnectionString;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 创建SPMS数据连接,连接状态为Closed
        public static SqlConnection CreateSqlConnection_SPMS()
        {
            try
            {
                SqlConnection conn_sql = new SqlConnection();
                conn_sql.ConnectionString = GetConnectionString_SPMS();
                CloseConnection_SQL(ref conn_sql);
                return conn_sql;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}
